//
//  UITableView+EmptyData.m
//  YueDongKe
//
//  Created by 司亚冰 on 15/12/14.
//  Copyright (c) 2015年 SP. All rights reserved.
//

#import "UITableView+EmptyData.h"

@implementation UITableView (EmptyData)

- (void) tableViewDisplayWithImageName:(NSString *)imgName msg:(NSString *)message ifNecessaryForRowCount:(NSUInteger) rowCount{
    if (rowCount == 0) {
        
        UILabel *messageLabel = [UILabel new];
        messageLabel.text = message;
        messageLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
        messageLabel.textColor = [UIColor lightGrayColor];
        messageLabel.textAlignment = NSTextAlignmentCenter;
        messageLabel.numberOfLines = 0;
        [messageLabel sizeToFit];
        self.backgroundView = messageLabel;
        
        UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 120, 120)];
        if (messageLabel.frame.origin.y < 0) {
            img.center = CGPointMake(messageLabel.center.x, messageLabel.center.y-45);

        }else{
        img.center = CGPointMake(messageLabel.center.x, messageLabel.center.y-85);
        }
        img.image = [UIImage imageNamed:imgName];
        [self.backgroundView addSubview:img];
    }else{
        self.backgroundView = nil;
    }
}

@end
